package org.edu.modules.stu.zhsz.service.impl;

import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.stu.base.service.VeStuFileService;
import org.edu.modules.stu.zhsz.mapper.VeStuMoralResourceMapper;
import org.edu.modules.stu.zhsz.entity.VeStuMoralResource;
import org.edu.modules.stu.zhsz.dto.VeStuMoralResourceDto;
import org.edu.modules.stu.zhsz.service.VeStuMoralResourceService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;



/**
 * 实现类
 */
@Service
public class VeStuMoralResourceServiceImpl extends BaseServiceImpl<VeStuMoralResource, VeStuMoralResourceMapper> implements VeStuMoralResourceService {

    @Autowired
    private VeStuFileService fileService;

    public IPage<VeStuMoralResourceDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeStuMoralResourceDto findDtoById(String id) {
        VeStuMoralResource entity = super.findById(id);
        VeStuMoralResourceDto dto = ConvertUtils.convertToDto(entity, VeStuMoralResourceDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeStuMoralResourceDto dto,Boolean isAdd){
        if(isAdd){
            dto.setTerminalId(1);
            super.insert(dto);
        }else{
            super.update(dto);
        }
        fileService.updateFiles(dto.getFileIds(),dto.getId()+"","veStuMoralResource");
    }

    @Override
    public void importExcel(List<Map<String, Object>> mapList){
        for (Map map: mapList) {
            VeStuMoralResourceDto dto = new VeStuMoralResourceDto();
                   //         dto.setTitle ((String)map.get(0000));
                   //         dto.setContent ((String)map.get(0000));
                   //         dto.setStatus ((String)map.get(0000));
                   //         dto.setFileId ((String)map.get(0000));
                   //         dto.setPushTime ((String)map.get(0000));
                   //         dto.setPushUserId ((String)map.get(0000));
                   //         dto.setPushUserName ((String)map.get(0000));

            super.insert(dto);
        }

    }

}
